//
//  FileHandler.m
//  AroundTheWorld
//
//  Created by IfelseGo on 16/6/5.
//  Copyright © 2016年 IfelseGo an. All rights reserved.
//

#import "FileHandler.h"

@implementation FileHandler
//找到缓存路径,读取缓存
- (float)clearCache
{
     float folderSize;
    NSArray *files = @[@"1HotTravel", @"1Recommend", @"2Destination", @"3CommunityDestination", @"3CommunityEnterLayout"];
    NSDictionary *attributes = [NSDictionary dictionary];
    NSFileManager *manager = [NSFileManager defaultManager];
    NSString *documentsPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).lastObject;
    
    for (NSInteger i = 0; i < [files count]; i++) {
        NSString *name = [files objectAtIndex:i];
        NSString *fileName = [name stringByAppendingString:@".plist"];
        NSString *path = [documentsPath stringByAppendingPathComponent:fileName];
        if ([manager fileExistsAtPath:path]) {
            
            attributes = [manager attributesOfItemAtPath:path error:nil];
            NSLog(@"%@: %@", fileName, [attributes objectForKey:NSFileSize]);
            [manager removeItemAtPath:path error:nil];
        }
        folderSize += [self fileSizePath:path];
    }
    return folderSize;
}

//缓存的计算
-(float)fileSizePath:(NSString *)path{
    NSFileManager *fileManager = [NSFileManager defaultManager];
    if ([fileManager fileExistsAtPath:path]) {
        long size = [fileManager attributesOfItemAtPath:path error:nil].fileSize;
        return size/1024.0/1024.0;
    }
    return 0;
}


@end
